package com.thrd.taiexhibition.model;

import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.thrd.basicframework.http.OkHttpUtils;
import com.thrd.basicframework.http.callback.ThrdCallBack;
import com.thrd.taiexhibition.bean.BeanCityInvestClimate;
import com.thrd.taiexhibition.bean.BeanCityInvestDay;
import com.thrd.taiexhibition.bean.BeanCityInvestment;
import com.thrd.taiexhibition.callback.MvpCallback;
import com.thrd.taiexhibition.utils.Constant;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: ${唐杰}
 * @date: 2021/3/25
 */
public class CityInvestmentEnvironmentModel {
    public static final String TAG="CityInvestmentEnvironmentModel";

    /**
     * 获取城市首页
     */
    public void getCityInvestmentEnvironmentData(long id,final MvpCallback<List<BeanCityInvestDay>> mvpCallback){
        OkHttpUtils.get().url(Constant.HTTP_CITY_INVESTMENT)
                .tag(TAG)
                .addParams("cityId",String.valueOf(id))
                .build().execute(new ThrdCallBack<List<BeanCityInvestDay>>() {
            @Override
            public void onFailed(String e, int code) {
                mvpCallback.onFailed(e,code);
            }

            @Override
            public void onResponse(List<BeanCityInvestDay> response, int id) {
                mvpCallback.onSuccess(response);
            }

            @Override
            public List<BeanCityInvestDay> onJson(String s) {
                BeanCityInvestment mBeanCityInvestment=    JSON.parseObject(s, BeanCityInvestment.class);
                BeanCityInvestClimate mBeanCityInvestClimate= mBeanCityInvestment.getCityInvestClimate();
                List<BeanCityInvestDay>  beanCityInvestDayList=new ArrayList<>();

                BeanCityInvestDay day1=new BeanCityInvestDay();

                if(mBeanCityInvestClimate==null|| TextUtils.isEmpty(mBeanCityInvestClimate.getTrafficImg())){
                    day1.setInvestType(2);
                }else{
                    day1.setInvestType(0);
                    day1.setImageBg(mBeanCityInvestClimate.getTrafficImg());
                    day1.setImageQrCode(mBeanCityInvestClimate.getTrafficQrCode());
                }

                beanCityInvestDayList.add(day1);

                BeanCityInvestDay day2=new BeanCityInvestDay();

                if(mBeanCityInvestClimate==null|| TextUtils.isEmpty(mBeanCityInvestClimate.getDevelopImg())){
                    day2.setInvestType(2);
                }else{
                    day2.setInvestType(0);
                    day2.setImageBg(mBeanCityInvestClimate.getDevelopImg());
                    day2.setImageQrCode(mBeanCityInvestClimate.getDevelopQrCode());
                }
                beanCityInvestDayList.add(day2);

                BeanCityInvestDay day3=new BeanCityInvestDay();

                if(mBeanCityInvestClimate==null|| mBeanCityInvestment.getCityInvestList()==null||mBeanCityInvestment.getCityInvestList().size()==0){
                    day3.setInvestType(2);
                }else{
                    day3.setInvestType(1);
                    day3.setBeanCityInvests(mBeanCityInvestment.getCityInvestList());
                    day3.setId(mBeanCityInvestClimate.getInvestIndustryExhibitId());
                    day3.setImageBg(mBeanCityInvestment.getCityInvestClimate().getInvestIndustryExhibitImg());
                }
                beanCityInvestDayList.add(day3);

                BeanCityInvestDay day4=new BeanCityInvestDay();
                if(mBeanCityInvestClimate==null|| TextUtils.isEmpty(mBeanCityInvestClimate.getMerchantsImg())){
                    day4.setInvestType(2);
                }else{
                    day4.setInvestType(0);
                    day4.setImageBg(mBeanCityInvestClimate.getMerchantsImg());
                    day4.setImageQrCode(mBeanCityInvestClimate.getMerchantsQrCode());
                }

                beanCityInvestDayList.add(day4);




                return beanCityInvestDayList;
            }


        });


    }
}
